<?php
// use the dPFramework to have easy database operations (store, delete etc.) by using its ObjectOrientedDesign
// therefore we have to create a child class for the module einstein

// a class named (like this) in the form: module/module.class.php is automatically loaded by the dPFramework

/**
 *	@package dotProject
 *	@subpackage modules
 *	@version $Revision: 1.0 $
*/

// include the powerful parent class that we want to extend for einstein
require_once( $AppUI->getSystemClass ('dp' ) );		// use the dPFramework for easy inclusion of this class here

/**
 * The Einstein Class
 */
class CMdJobTitle extends CDpObject {
	// link variables to the einstein object (according to the existing columns in the database table einstein)
	var $jobtitle_id = NULL;	//use NULL for a NEW object, so the database automatically assigns an unique id by 'NOT NULL'-functionality
	var $jobtitle_code = NULL;	//use NULL for a NEW object, so the database automatically assigns an unique id by 'NOT NULL'-functionality
	var $jobtitle_name = NULL;	//use NULL for a NEW object, so the database automatically assigns an unique id by 'NOT NULL'-functionality
	var $jobtitle_active = 1;

	// the constructor of the CEinstein class, always combined with the table name and the unique key of the table
	function CMdJobTitle() {
		$joins = array(
			array('label'=>'Resource',name=>'contacts', 'idfield'=>'contact_id', 'joinfield'=>'contact_jobtitle'),
		);
		$this->CDpObject( 'md_jobtitle', 'jobtitle_id', 'jobtitle_code', $joins, 'masterdata');
	}

	function check() {
		if (!isset($this->_tbl_unique) || $this->_tbl_unique == NULL) {
			return NULL;
		}
		$q = new DBQuery();
		$q->addTable("$this->_tbl");
		$q->addWhere("$this->_tbl_key != $this->jobtitle_id");
		$q->addWhere("$this->_tbl_unique = '$this->jobtitle_code'");
		$result = $q->loadResult();
		if (isset($result) && $result != '') {
			return 'Duplicate jobtitle code: ' . $this->jobtitle_code;
		}
		return NULL;
	}
}
?>